﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Collections;
namespace vfife_building_algorithm
{
    public partial class ElementForce_Specify : Form
    {
        
        private Hashtable htElmts;
        
        public ElementForce_Specify()
        {
            InitializeComponent();

            htElmts = Model.Elements;

            // set combobox with element ID
            DataGridViewComboBoxColumn elementId = SetElementForce.Columns[0] as DataGridViewComboBoxColumn;
            elementId.Items.Clear();
            foreach (DictionaryEntry de in htElmts)
            {
                elementId.Items.Add(de.Key.ToString());

            }
            DataGridViewComboBoxColumn LoadingWay = SetElementForce.Columns[2] as DataGridViewComboBoxColumn;
            LoadingWay.Items.Clear();
            LoadingWay.Items.Add("RAMP");
        }

        private void Done_Click(object sender, EventArgs e)
        {
            int iRowNb = SetElementForce.RowCount;
            for (int i = 0; i < iRowNb; i++)
            {
                DataGridViewRow rowElmtForce = SetElementForce.Rows[i];
                //check if there exists empty value(s)
                if (null == rowElmtForce.Cells[0].Value || null == rowElmtForce.Cells[1].Value ||
                    null == rowElmtForce.Cells[2].Value )
                { continue; }

                int ElmtId = int.Parse(rowElmtForce.Cells[0].Value.ToString());
                double lamd  = double.Parse(rowElmtForce.Cells[1].Value.ToString());
                string LoadingWay= rowElmtForce.Cells[2].Value.ToString();
                Caculation_Parameters cacu_Para = Model.Caculation_parameters;
                ElementForce elforce = new ElementForce(lamd, cacu_Para);
                Ramp_Setting rmp_setting;
                if (LoadingWay.Equals("RAMP"))
                {
                    rmp_setting= new Ramp_Setting(elforce);
                    rmp_setting.Show();
                    ((Element)htElmts[ElmtId]).Elementforce = rmp_setting.elforce;
                }
                
            }

            this.Close();
        }
        private double ramp_step(double rtime, double time)
        {
            double Pt;
            if (time > rtime)
            {
                Pt = 1.0;
            }
            else
            {
                Pt = time / rtime;
            }
            return Pt;
        }

        private void SetElementForce_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            
        }
    }
}
